<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/WEB-INF/jsp/common/tags.jsp"%>

<aos:html title="分类管理" base="http" lib="ext">
<aos:body>
</aos:body>
</aos:html>


<aos:onready>
	<aos:viewport layout="border">
		<aos:formpanel id="_f_query" layout="column" labelWidth="20"
			header="false" region="north" border="false">
			<aos:dockeditem xtype="button" text="添加新分类" onclick="_w_info_add_show()" icon="add.png" />
			<aos:dockeditem xtype="button" text="添加子分类" onclick="_w_type_add_show()" icon="add.png" />
			<aos:dockeditem xtype="tbfill" />
		</aos:formpanel>



		<aos:gridpanel id="_g_info" url="cataService.cataList" onitemclick="fn_g_cata_click"
			onrender="_g_info_query" region="center" minHeight="200" pageSize="20">
			<aos:docked forceBoder="1 0 1 0">
				<aos:dockeditem xtype="tbtext" text="商品分类" />
			</aos:docked>
			<aos:column type="rowno" />
			<aos:column header="分类编号" dataIndex="id" />
			<aos:column header="分类名称" dataIndex="name" />
			<aos:column header="排序" dataIndex="sort" />
			<aos:column header="是否有效" dataIndex="is_valid" rendererField="is_" />
			<aos:column header="创建时间" dataIndex="create_date" type="date"
				format="Y-m-d H:i:s" />
			<aos:column header="修改时间" dataIndex="modify_date" type="date"
				format="Y-m-d H:i:s" />
			<aos:column header="编辑" rendererFn="fn_button_render" align="center"
				fixedWidth="60" />
		</aos:gridpanel>


		<aos:panel region="south" minHeight="200" maxHeight="400">
			<aos:gridpanel id="_g_type" region="center"
				url="typeService.typeList" onrender="_g_type_query">
				<aos:docked forceBoder="1 0 1 0">
					<aos:dockeditem xtype="tbtext" text="产品子分类" />
				</aos:docked>
				<aos:column type="rowno" />
				<aos:column header="子类型id" dataIndex="id"  />
				<aos:column header="分类" dataIndex="cata_id" rendererField="catalogy_type_"/>
				<aos:column header="名称" dataIndex="name" />
				<aos:column header="排序" dataIndex="sort" />
				<aos:column header="是否有效" dataIndex="is_valid" rendererField="is_" />
				<aos:column header="编辑" rendererFn="fn_button_type_edit" align="center" />
                <aos:column header="删除" rendererFn="fn_button_type_del" align="center" />
			</aos:gridpanel>
		</aos:panel>


		<aos:window id="_w_query" title="查询条件" onshow="_w_query_onshow">
			<aos:formpanel id="_f_pf_query" width="400" layout="anchor"
				labelWidth="70">
				<aos:textfield name="cata_id" fieldLabel="产品id" />
			</aos:formpanel>
		</aos:window>






		<aos:window id="_w_info" title="编辑分类" onshow="_w_info_onshow">
			<aos:formpanel id="_f_info" width="400" layout="anchor"
				labelWidth="70">
				<aos:numberfield name="id" fieldLabel="分类编号" readOnly="true" />
				<aos:textfield name="name" fieldLabel="名称" />
				<aos:numberfield name="sort" fieldLabel="排序" />
				<aos:combobox name="is_valid" fieldLabel="是否有效" dicField="is_" />
			</aos:formpanel>
			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="updateCata" text="提交" icon="ok.png" />
				<aos:dockeditem onclick="#_w_info.hide();" text="关闭"
					icon="close.png" />
			</aos:docked>
		</aos:window>

		<aos:window id="_w_add_info" title="添加分类" onshow="_w_info_add_onshow">
			<aos:formpanel id="_f_info_add" width="400" layout="anchor"
				labelWidth="70">
				<aos:numberfield name="id" fieldLabel="分类编号" />
				<aos:textfield name="name" fieldLabel="名称" />
				<aos:numberfield name="sort" fieldLabel="排序" />
				<aos:combobox name="is_valid" fieldLabel="是否有效" dicField="is_" />
			</aos:formpanel>
			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="addCate()" text="提交" icon="ok.png" />
				<aos:dockeditem onclick="#_w_add_info.hide();" text="关闭"
					icon="close.png" />
			</aos:docked>
		</aos:window>


       <aos:window id="_w_type" title="子分类编辑"	onshow="_w_type_onshow">
			<aos:formpanel id="_f_type" width="400" layout="anchor"	labelWidth="70">
				<aos:numberfield name="id" fieldLabel="小分类编号" />
				<aos:combobox name="cata_id" fieldLabel="大类id"  dicField="catalogy_type_"/>
				<aos:textfield name="name" fieldLabel="名称" />
				<aos:numberfield name="sort" fieldLabel="排序" />
				<aos:combobox name="is_valid" fieldLabel="是否有效" dicField="is_" />
			</aos:formpanel>
			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="updateType()" text="提交" icon="ok.png" />
				<aos:dockeditem onclick="#_w_type.hide();" text="关闭" icon="close.png" />
			</aos:docked>
		</aos:window>

        <aos:window id="_w_type_add" title="子分类添加"	onshow="_w_type_add_onshow">
			<aos:formpanel id="_f_type_add" width="400" layout="anchor"	labelWidth="70">
				<aos:numberfield name="id" fieldLabel="小分类编号" />
				<aos:combobox name="cata_id" fieldLabel="大类id"  dicField="catalogy_type_"/>
				<aos:textfield name="name" fieldLabel="名称" />
				<aos:numberfield name="sort" fieldLabel="排序" />
				<aos:combobox name="is_valid" fieldLabel="是否有效" dicField="is_" />
			</aos:formpanel>
			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="addType()" text="提交" icon="ok.png" />
				<aos:dockeditem onclick="#_w_type_add.hide();" text="关闭" icon="close.png" />
			</aos:docked>
		</aos:window>





	</aos:viewport>

	<script type="text/javascript">
		//加载表格数据
		function _g_info_query() {
			_g_info_store.loadPage(1);
		}
		
		
		 function _g_type_query() {
			 var params = AOS.getValue('_f_pf_query');
		     _g_type_store.getProxy().extraParams = params;
			 _g_type_store.loadPage(1);
		 }
		
		 
			//表格单击事件
		function fn_g_cata_click(obj, record) {
			AOS.setValue('_f_pf_query.cata_id', record.data.id);
			_g_type_query();
		}
		
		
		
		
		
		//窗口弹出事件监听
		function _w_info_onshow() {
			var record = AOS.selectone(_g_info);
            AOS.ajax({
            	params : {
            		id: record.data.id
            	},
                url: 'cataService.getCata',
                ok: function (data) {
                	_f_info.form.setValues(data);
                }
            });
		}
		
		
		function _w_type_onshow() {
			var record = AOS.selectone(_g_type);
            AOS.ajax({
            	params : {
            		id: record.data.id
            	},
                url: 'typeService.getType',
                ok: function (data) {
                	_f_type.form.setValues(data);
                }
            });
		}
		
		
		
		
		
		//更新
		function updateCata() {
			AOS.ajax({
				forms : _f_info,
                url: 'cataService.updateCata',
                ok: function (data) {
                	AOS.tip(data.appmsg);
					_g_info_store.reload();
					_w_info.hide();
                }
            });
		}
		
		function updateType() {
			AOS.ajax({
				forms : _f_type,
                url: 'typeService.updateType',
                ok: function (data) {
                	AOS.tip(data.appmsg);
					_g_type_store.reload();
					_w_type.hide();
                }
            });
		}
		
		
		
		
		
		//添加产品
		function addCata() {
			AOS.ajax({
				forms : _f_info_add,
                url: 'cataService.addCata',
                ok: function (data) {
                	AOS.tip(data.appmsg);
					_g_info_store.reload();
					_w_add_info.hide();
                }
            });
		}
		
		function addType() {
			AOS.ajax({
				forms : _f_type_add,
                url: 'typeService.addType',
                ok: function (data) {
                	AOS.tip(data.appmsg);
					_g_type_store.reload();
					_w_type_add.hide();
                }
            });
		}
		
		
		
		
		
		//按钮列转换
		function fn_button_render(value, metaData, record, rowIndex, colIndex,
				store) {
			return '<input type="button" value="编辑" class="cbtn" onclick="_w_info_show();" />';
		}
		
		
		
		function fn_button_type_edit(value, metaData, record, rowIndex, colIndex,
				store) {
			return '<input type="button" value="编辑" class="cbtn" onclick="_w_type_show()" />';
		}
		
		
		
		function fn_button_type_del(value, metaData, record, rowIndex, colIndex,
				store) {
			return '<input type="button" value="删除" class="cbtn" onclick="_w_type_del(\''+record.data.id+'\')" />';
		}
		
		
		
		
	</script>
</aos:onready>

<script type="text/javascript">

	//显示编辑窗口
	function _w_info_show(){
		Ext.getCmp('_w_info').show();
	}
	
	
	function _w_info_add_show(){
		Ext.getCmp('_w_add_info').show();
	}
	
	
	function _w_type_show(){
		Ext.getCmp('_w_type').show();
	}
	
	function _w_type_add_show(){
		Ext.getCmp('_w_type_add').show();
	}
	
	
	
	function _w_type_del(id){
		var msg =  AOS.merge('确认要删除吗？');
		AOS.confirm(msg, function(btn){
			if(btn === 'cancel'){
				AOS.tip('删除操作被取消。');
				return;
			}
			AOS.ajax({
				url : 'typeService.deleteType',
				params:{
					id: id
				},
				ok : function(data) {
					AOS.tip(data.appmsg);
					AOS.get('_g_type').getStore().reload();
				}
			});
		});
	}
	
	
	
</script>